#ifndef	__UNET_H__
#define	__UNET_H__

#include "pcap.h"
#include "unistd.h"
#include "fcntl.h"
#include "sys/stat.h"

#include "arpa/inet.h"
#include "linux/if_ether.h"
#include "linux/ip.h"
#include "netinet/tcp.h"
#include "linux/udp.h"
#include "common.h"

/* structs */
struct toption{
	uint8_t	kind;	//tcp option kind
	uint8_t	len;	//option length
	uint8_t *info;	//info
};
struct utcphdr{
	struct tcphdr	*tcphd;
	struct toption	*option;
};
struct hdr{
	struct ethhdr	*ethhd;
	struct iphdr	*iphd;
	union{
		struct utcphdr	*utcphd;
		struct udphdr	*udphd;
	}tuhd;
};

/**
* save capture packet
**/
inline void save_packet(const void *data, int len, const char *fname);

/* chechsum */
uint16_t checksum(uint16_t *data, int num);

/**
* get net packet header
* ntohl may need to be called when use head
**/
int get_header(void *pkt, int len, struct hdr *head);

/* getPacket that used in pcap_loop*/
void getPacket(u_char * arg, const struct pcap_pkthdr * pkthdr, const u_char * packet);

/**
* read local binary file and send them
* show in stdout when flag is set
* fd file decripter
**/
int restream(const char *fname, int fd, int flag);

#endif